package com.xoms.front.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xoms.front.cache.dao.RoomCache;
import com.xoms.front.controller.res.ListResult;
import com.xoms.front.controller.res.bean.RCardInfoBean;
import com.xoms.front.controller.res.bean.RFilmListBean;
import com.xoms.front.controller.res.bean.ROrderInfoBean;
import com.xoms.front.controller.res.bean.ROrderPayBean;
import com.xoms.front.controller.res.bean.RRoomBookInfoBean;
import com.xoms.front.controller.res.bean.RRoomDimensionBean;
import com.xoms.front.controller.res.bean.RRoomDimensionDetailBean;
import com.xoms.front.controller.res.bean.RRoomInfoBean;
import com.xoms.front.controller.res.bean.RRoomListBean;
import com.xoms.front.controller.res.bean.RRoomPriceBean;
import com.xoms.front.controller.res.bean.RRoomStatusListBean;
import com.xoms.front.controller.res.bean.RUserInfoBean;
import com.xoms.front.controller.springmvc.req.CreateChangeOrderParam;
import com.xoms.front.controller.springmvc.req.CreateOrderParam;
import com.xoms.front.controller.springmvc.req.CreateTimeOrderParam;
import com.xoms.front.controller.springmvc.req.EditOrderAuthPriceParam;
import com.xoms.front.controller.springmvc.req.GetByIdParam;
import com.xoms.front.controller.springmvc.req.GetFilmListParam;
import com.xoms.front.controller.springmvc.req.GetRoomDimensionDetailsParam;
import com.xoms.front.controller.springmvc.req.GetRoomListParam;
import com.xoms.front.controller.springmvc.req.GetUserInfoByCardParam;
import com.xoms.front.controller.springmvc.req.GetUserInfoByTelParam;
import com.xoms.front.controller.springmvc.req.RoomLockParam;
import com.xoms.front.controller.springmvc.req.RoomOpenParam;
import com.xoms.front.controller.springmvc.req.RoomOrderPayWayParam;
import com.xoms.front.model.AccountBean;
import com.xoms.front.model.MemberBean;
import com.xoms.front.model.OrderBean;
import com.xoms.front.model.RoomChangeBean;
import com.xoms.front.model.RoomDimensionBean;
import com.xoms.front.model.RoomOpenAddBean;
import com.xoms.front.model.RoomOpenBean;
import com.xoms.front.persist.dao.RoomDao;
import com.xoms.front.service.RoomService;
import com.xoms.front.service.exception.ServiceException;
import com.xoms.front.service.res.PageResult;
import com.xoms.util.AppTextUtil;
import com.xoms.util.DateTimeUtil;
import com.xoms.util.NumUtil;
import com.xoms.util.StringUtil;

/**
 * Created with IntelliJ IDEA.
 * User: tzz(Tian)
 * Date: 2018/5/25 14:56
 */

@Service
public class RoomServiceImpl implements RoomService {
    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    RoomDao roomImpl;

    @Autowired
    RoomCache roomCacheImpl;

    @Override
    public PageResult<RRoomDimensionBean> getRoomDimensions() {
        PageResult<RRoomDimensionBean> result = new PageResult<RRoomDimensionBean>();
        List<RoomDimensionBean> resultList = roomImpl.selectDimensions();
        List<RRoomDimensionBean> resList = new ArrayList<RRoomDimensionBean>();
        if (resultList != null) {
            RRoomDimensionBean rar = null;
            for (RoomDimensionBean res : resultList) {
                rar = new RRoomDimensionBean();

                BeanUtils.copyProperties(res, rar);
                resList.add(rar);
            }
        }
        result.setData(resList);
        result.setCount(resList.size());

        return result;
    }

    @Override
    public ListResult<RRoomDimensionDetailBean> getDimensionDetails(GetRoomDimensionDetailsParam param) {
        ListResult<RRoomDimensionDetailBean> result = new ListResult<RRoomDimensionDetailBean>();
        List<RRoomDimensionDetailBean> resList = roomImpl.getDimensionDetailList(param);
        result.setData(resList);
        result.setTotalSize(resList.size());
        return result;
    }

    @Override
    public ListResult<RRoomStatusListBean> getRoomStatusList(String scales) {
        ListResult<RRoomStatusListBean> result = new ListResult<RRoomStatusListBean>();
        List<RRoomStatusListBean> resList = roomImpl.getRoomStatusList(scales);
        result.setData(resList);
        result.setTotalSize(resList.size());
        return result;
    }

    @Override
    public ListResult<RRoomListBean> getRoomList(GetRoomListParam param) {
        ListResult<RRoomListBean> result = new ListResult<RRoomListBean>();
        List<RRoomListBean> resList = roomImpl.getRoomList(param);
        result.setData(resList);
        result.setTotalSize(resList.size());
        return result;
    }

    @Override
    public ListResult<RRoomBookInfoBean> getRoomBookList(GetByIdParam param) {
        ListResult<RRoomBookInfoBean> result = new ListResult<RRoomBookInfoBean>();
        List<RRoomBookInfoBean> resList = roomImpl.getRoomBookList(param.getId());
        result.setData(resList);
        result.setTotalSize(resList.size());
        return result;
    }

    @Override
    public ListResult<RFilmListBean> getFilmList(GetFilmListParam param) {
        ListResult<RFilmListBean> result = new ListResult<RFilmListBean>();
        List<RFilmListBean> resList = roomImpl.getFilmList(param);
        result.setData(resList);
        result.setTotalSize(resList.size());
        return result;
    }

    @Override
    public RUserInfoBean getUserInfoByCard(GetUserInfoByCardParam param) {
        RUserInfoBean bean = new RUserInfoBean();
        RCardInfoBean card = roomImpl.getCardInfo(param.getCardNo());
        if (card == null) {
            throw new ServiceException("object_is_not_exist","卡信息");
        }
        MemberBean member = roomImpl.getMember(card.getUid(), null);
        BeanUtils.copyProperties(member, bean);
        List<RCardInfoBean> list = new ArrayList<>();
        list.add(card);
        bean.setCardList(list);
        return bean;
    }

    @Override
    public RUserInfoBean getUserInfoByTel(GetUserInfoByTelParam param) {
        RUserInfoBean bean = new RUserInfoBean();
        MemberBean member = roomImpl.getMember(null, param.getPhoneNum());
        if (member == null) {
            throw new ServiceException("object_is_not_exist","会员信息");
        }
        BeanUtils.copyProperties(member, bean);
        List<RCardInfoBean> list = roomImpl.getCardList(member.getUid(), 1);
        if (list.size() == 0) {
            // 没有可以登陆的卡
            throw new ServiceException("operate_need_confirm"," 当前手机号无匹配卡可用于登陆，");
        }
        bean.setCardList(list);
        return bean;
    }

    @Override
    public String roomLock(AccountBean account, RoomLockParam param) {
        RRoomInfoBean room = roomImpl.selectRoomById(param.getId());
        if (room.getStatus() != 1) {
            throw new ServiceException("operate_need_confirm","影厅状态处于非空闲状态，无法锁定，");
        }
        String date = roomCacheImpl.setRoomLock(param.getId(), account.getAccid(), 70);
        if (date == null) {
            throw new ServiceException("operate_need_confirm"," 已被占用，锁定失败，");
        }
        return date;
    }

    @Override
    public void roomUnLock(AccountBean account, RoomLockParam param) {
        roomCacheImpl.clearRoomLock(param.getId(), account.getAccid());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ROrderInfoBean createOrder(AccountBean account, CreateOrderParam param) {
        ROrderInfoBean res = new ROrderInfoBean();
        RRoomInfoBean room = roomImpl.selectRoomById(param.getId());
        if (room == null) {
            throw new ServiceException("object_is_not_exist","影厅");
        }
        if (room.getStatus() != 1) {
            throw new ServiceException("object_exception_fail","影厅未处于空闲状态，");
        }

        if (param.getIsMember() == 1) {
            if (StringUtil.isEmpty(param.getCardNo())) {
                throw new ServiceException("param_input_is_not_empty", "会员卡号");
            }
            RCardInfoBean card = roomImpl.getCardInfo(param.getCardNo());
            if (card == null) {
                throw new ServiceException("object_is_not_exist","卡信息");
            }
        } else {
            param.setCardNo(null);
        }
        OrderBean order = new OrderBean();
        RoomOpenBean open = new RoomOpenBean();
        BeanUtils.copyProperties(param, order);

        if (param.getHours() <= 0) {
            throw new ServiceException("param_is_error", "开厅时长");
        }
        order.setOid(AppTextUtil.getPrimaryKey());
        order.setOrderNo(AppTextUtil.getRandomNo());
        order.setSubject("开厅-"+room.getName());
        order.setRoomId(room.getId());
        order.setActionId(account.getAccid());
        order.setTheatreCode(room.getTheatreId());
        order.setOrderType(1);

//            ROrderInfoBean rorder = getPrice(param.getId(), DateTimeUtil.formatTimestamp(param.getStartTime(), null), DateTimeUtil.formatTimestamp(param.getEndTime(), null));
        long btime = DateTimeUtil.formatTimestamp(DateTimeUtil.getCurrentTimestamp());
        long etime = btime + param.getHours()*60*60;

        open.setStartTime(new Timestamp(btime*1000));
        open.setEndTime(new Timestamp(etime*1000));

        if (!isValidOfRoom(room, open.getEndTime(), open.getPhoneNum()))
            throw new ServiceException("operate_need_confirm", "在您选择的使用时间内，与其它用户的预定相冲突，无法创建，");

        ROrderInfoBean rorder = getPrice(param.getId(), DateTimeUtil.formatTimestamp(btime, null), DateTimeUtil.formatTimestamp(etime, null));
        res.setCalculate(rorder.getCalculate());
        // 计算费用
//            order.setMoney(getPrice(param.getId(), DateTimeUtil.formatTimestamp(param.getStartTime(), null), DateTimeUtil.formatTimestamp(param.getEndTime(), null)));
        order.setMoney(rorder.getMoney());

        BeanUtils.copyProperties(param, open);
        open.setSid(AppTextUtil.getPrimaryKey());
        open.setOrderCode(order.getOrderNo());
        open.setRoomId(room.getId());
        open.setAccountId(account.getAccid());
        open.setHours(param.getHours());
        open.setIsMember(param.getIsMember());
        open.setMemberId(param.getCardNo());

        Boolean flag = roomImpl.createOrder(order, open, null) > 0;
        if(!flag) {
            throw new ServiceException("database_insert_fail","创建订单");
        }

        BeanUtils.copyProperties(order, res);
        return res;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ROrderInfoBean createTimeOrder(AccountBean account, CreateTimeOrderParam param) {
        if (param.getHours() <= 0) {
            throw new ServiceException("param_is_error", "续厅时长");
        }
        ROrderInfoBean res = new ROrderInfoBean();
        RRoomInfoBean room = roomImpl.selectRoomById(param.getId());
        if (room == null) {
            throw new ServiceException("object_is_not_exist","影厅");
        }
        // 获取影厅当前有效订单（使用中）
        OrderBean curr_order = roomImpl.getCurrentOrder(room.getId());
        if (curr_order == null) {
            throw new ServiceException("object_is_not_exist","影厅当前最新有效订单");
        }

        // 新的订单信息
        OrderBean newOrder = new OrderBean();

        // 续时、转厅等关联开定订单表
        if (curr_order.getOrderType() == 1) {
            // 当前订单是开厅订单，没有转厅
            newOrder.setTargetId(curr_order.getOrderNo());
        } else if (curr_order.getOrderType() == 3) {
            // 当前订单是转厅订单，再次续时
            newOrder.setTargetId(curr_order.getTargetId());
        }

        // 从下一秒开始
        long btime = room.getEndTime()+1;
        long etime = btime + param.getHours()*60*60;

        RoomOpenBean open = roomImpl.getRoomOpenOrder(newOrder.getTargetId());
        if (!isValidOfRoom(room, new Timestamp(etime*1000), open.getPhoneNum()))
            throw new ServiceException("operate_need_confirm", "在您选择的使用时间内，与其它用户的预定相冲突，无法创建，");

        // 计算费用
        ROrderInfoBean rorder = getPrice(room.getId(), DateTimeUtil.formatTimestamp(btime, null), DateTimeUtil.formatTimestamp(etime, null));
        res.setCalculate(rorder.getCalculate());
        res.setMoney(rorder.getMoney());
        newOrder.setMoney(rorder.getMoney());

        newOrder.setOid(AppTextUtil.getPrimaryKey());
        newOrder.setOrderNo(AppTextUtil.getRandomNo());
        newOrder.setSubject("续时-"+room.getName()+"("+param.getHours()+"小时)");
        newOrder.setRoomId(room.getId());
        newOrder.setActionId(account.getAccid());
        newOrder.setTheatreCode(room.getTheatreId());
        newOrder.setActionId(account.getAccid());
        newOrder.setOrderType(2);

        RoomOpenAddBean openAdd = new RoomOpenAddBean();
        openAdd.setAid(AppTextUtil.getPrimaryKey());
        openAdd.setOrderCode(newOrder.getOrderNo());
        openAdd.setStartTime(new Timestamp(btime*1000));
        openAdd.setHour(param.getHours());
        openAdd.setEndTime(new Timestamp(etime*1000));
        openAdd.setAccountId(account.getAccid());
        // 关联订单ID
//        openAdd.setOrderId(newOrder.getOrderNo());

        Boolean flag = roomImpl.createOrder(newOrder, null, openAdd) > 0;
        if(!flag) {
            throw new ServiceException("database_insert_fail","创建 续时订单");
        }

        res.setOid(newOrder.getOid());
        res.setOrderNo(newOrder.getOrderNo());
        return res;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ROrderInfoBean createChangeOrder(AccountBean account, CreateChangeOrderParam param) {
        ROrderInfoBean res = new ROrderInfoBean();
        RRoomInfoBean room = roomImpl.selectRoomById(param.getId());
        if (room == null) {
            throw new ServiceException("object_is_not_exist","影厅");
        }
        if (room.getStatus() != 3) {
            throw new ServiceException("operate_need_confirm","当前影厅当前并未使用，无法发起转厅操作");
        }
        RRoomInfoBean newroom = roomImpl.selectRoomById(param.getNewId());
        if (newroom == null) {
            throw new ServiceException("object_is_not_exist","目标影厅");
        }
        if (newroom.getStatus() != 1) {
            throw new ServiceException("operate_need_confirm","目标影厅当前非空闲状态，");
        }
        // 计算剩余时间
        int minute = (int)(room.getEndTime()-DateTimeUtil.formatTimestamp(DateTimeUtil.getCurrentTimestamp())) / 60;

        // 获取影厅当前有效订单（使用中）
        OrderBean curr_order = roomImpl.getCurrentOrder(room.getId());
        if (curr_order == null) {
            throw new ServiceException("object_is_not_exist","影厅当前最新有效订单");
        }
        String openOrder = "";
        // 续时、转厅等关联开定订单表
        if (curr_order.getOrderType() == 1) {
            // 当前订单是开厅订单，没有转厅
            openOrder = curr_order.getOrderNo();
        } else if (curr_order.getOrderType() == 3) {
            // 当前订单是转厅订单，再次续时
            openOrder = curr_order.getTargetId();
        }
        RoomOpenBean open = roomImpl.getRoomOpenOrder(openOrder);
        if (!isValidOfRoom(room, new Timestamp(room.getEndTime()), open.getPhoneNum()))
            throw new ServiceException("operate_need_confirm", "在您选择的使用时间内，与其它用户的预定相冲突，无法创建，");

        OrderBean order = new OrderBean();
        RoomChangeBean change = new RoomChangeBean();

        BeanUtils.copyProperties(open, curr_order);
        order.setOid(AppTextUtil.getPrimaryKey());
        order.setOrderNo(AppTextUtil.getRandomNo());
        order.setSubject("转厅-"+room.getName());
        order.setRoomId(newroom.getId());
        order.setActionId(account.getAccid());
        order.setTheatreCode(room.getTheatreId());
        order.setTargetId(openOrder);
        order.setOrderType(3);

        long btime = DateTimeUtil.formatTimestamp(DateTimeUtil.getCurrentTimestamp());
        long etime = btime + minute*60;
        ROrderInfoBean rorder = getPrice(room.getId(), DateTimeUtil.formatTimestamp(btime, null), DateTimeUtil.formatTimestamp(etime, null));
        ROrderInfoBean rordernew = getPrice(newroom.getId(), DateTimeUtil.formatTimestamp(btime, null), DateTimeUtil.formatTimestamp(etime, null));
        if (rorder.getMoney() == rordernew.getMoney()) {
            order.setMoney(0.0);
            order.setGetMoney(0.0);
            change.setPayStatus(1);
        } else if (rorder.getMoney() < rordernew.getMoney()) {
            // 补
            res.setCalculate(rordernew.getCalculate()+"-"+rorder.getMoney());
            order.setMoney(rordernew.getMoney() - rorder.getMoney());
            change.setPayStatus(0);
        } else {
            res.setCalculate(rorder.getMoney() + "-" + rordernew.getCalculate());
            order.setMoney(rordernew.getMoney() - rorder.getMoney());
            order.setGetMoney(rordernew.getMoney() - rorder.getMoney());
            change.setPayStatus(1);
        }

        change.setCid(AppTextUtil.getPrimaryKey());
        change.setOrderCode(order.getOrderNo());
        change.setAccountId(account.getAccid());
        change.setStartTime(new Timestamp(btime*1000));
        change.setEndTime(new Timestamp(etime*1000));
        change.setMinute(minute);

        Boolean flag = roomImpl.createOrder(order, open, null) > 0;
        if(!flag) {
            throw new ServiceException("database_insert_fail","创建订单");
        }

        BeanUtils.copyProperties(order, res);
        return res;
    }

    @Override
    public ROrderInfoBean setOrderAuthPirce(EditOrderAuthPriceParam param) {
        ROrderInfoBean res = new ROrderInfoBean();
        OrderBean order = roomImpl.selectRoomOrder(param.getId(), null, null);
        if (order == null) {
            throw new ServiceException("object_is_not_exist","订单");
        }

        AccountBean acc = roomImpl.selectAccountByTel(param.getAuthPhoneNum());
        if (acc == null) {
            throw new ServiceException("object_is_not_exist","授权者账号信息");
        }
        Boolean flag = roomImpl.setOrderAuthPrice(param, acc.getAccid()) > 0;
        if(!flag) {
            throw new ServiceException("database_insert_fail","订单设置授权价格");
        }

        order = roomImpl.selectRoomOrder(param.getId(), null, null);
        BeanUtils.copyProperties(order, res);
        return res;
    }

    @Override
    public Boolean roomOpen(RoomOpenParam param) {
        RRoomInfoBean room = roomImpl.selectRoomById(param.getId());
        if (room == null) {
            throw new ServiceException("object_is_not_exist","影厅");
        }
        if (room.getStatus() != 1) {
            throw new ServiceException("object_exception_fail","影厅未处于空闲状态，");
        }
        OrderBean order = roomImpl.selectRoomOrder(param.getOid(), null, null);
        if (order == null) {
            throw new ServiceException("object_is_not_exist","支付订单");
        }
        if (order.getPayType() == null) {
            throw new ServiceException("object_exception_fail", "请先选择支付方式进行支付，");
        }
        if (order.getStatus() != 1 && order.getPayType() != 7) {
            throw new ServiceException("object_exception_fail", "订单未支付成功/签单，无法开厅，");
        }
        Boolean flag = roomImpl.roomOpen(param) > 0;
        if(!flag) {
            throw new ServiceException("database_insert_fail","影厅开厅");
        }
        return flag;
    }

    @Override
    public ROrderPayBean orderPayWay(RoomOrderPayWayParam param) {
        OrderBean order = roomImpl.selectRoomOrder(param.getId(), null, null);
        if (order == null) {
            throw new ServiceException("object_is_not_exist","订单");
        }
        if (order.getStatus() == 1)
            throw new ServiceException("operate_need_confirm","请勿重复支付,");
        if (order.getPayType() != null && order.getPayType() == 7)
            throw new ServiceException("operate_need_confirm","已经签单支付,");

        if (order.getOrderType() != 1 && order.getOrderType() != 2 && order.getOrderType() != 3)
            throw new ServiceException("object_exception_fail","只可以支付开厅、续时、转厅订单,");
        if (param.getIsHand() == 1) {
            if (StringUtil.isEmpty(param.getHandRoomId()))
                throw new ServiceException("operate_need_confirm","请选择被挂账的影厅,");
            if (!order.getRoomId().equals(param.getHandRoomId())) {
                // 要挂到其它影厅的时候，需要验证影厅信息，被挂账的影厅需要未结束 理论上被挂账的影厅需要在其它影厅消费之后才可以结束
                RRoomInfoBean room = roomImpl.selectRoomById(param.getHandRoomId());
                if (room == null)
                    throw new ServiceException("operate_need_confirm","被挂账的影厅不存在,");
                if (room.getStatus() != 3)
                    throw new ServiceException("operate_need_confirm","被挂账的影厅当前未开厅,");
                // 判断被挂账的影厅的订单支付方式
                OrderBean handOrder = roomImpl.selectRoomOrder(null, room.getId(), null);
                if (handOrder.getPayType() != 1 && handOrder.getPayType() != 8 && handOrder.getPayType() != 9)
                    throw new ServiceException("operate_need_confirm","被挂账的影厅的支付方式不是挂账/预付/签单/会员卡支付方式，无法挂账");
                // 判断额度是否足够
                if (handOrder.getPayType() == 9 && handOrder.getGetMoney() - handOrder.getMoney() - order.getMoney() < 0) {
                    throw new ServiceException("operate_need_confirm","被挂账的影厅的支付方式是预付，但额度不足支付两个影厅，无法挂账");
                }
                // TODO 是滞要判断所有挂账在某个影厅下的金额是否足额
                // TODO 签单方式支付的，需要判断信息额度是否够
            }
        } else {
            param.setHandRoomId(null);
        }

//        支付方式：1会员卡支付2现金3银联4支付宝5微信6信用卡7签单8挂账9预付款
        switch (param.getPayWay()) {
            case 1:
//                roomImpl.orderPayByCard(param);
                break;
            case 2:
                if (param.getGetMoney().doubleValue()!=order.getMoney().doubleValue()) {
                    throw new ServiceException("param_is_error", "实收金额");
                }
                roomImpl.orderPayWay(param, order.getOrderType());
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                break;
            case 6:
                break;
            case 7:
                roomImpl.orderPayWay(param, order.getOrderType());
                break;
            case 8:
                roomImpl.orderPayWay(param, order.getOrderType());
                break;
            case 9:
                break;
            default:
                throw new ServiceException("param_is_error", "支付方式");
        }

        ROrderPayBean res = new ROrderPayBean();
        res.setId(order.getOid());
        res.setTradeNo(order.getTradeNo());
        res.setPayWay(param.getPayWay());
        return res;
    }

    @Override
    public RRoomInfoBean getRoomInfo(GetByIdParam param) {
        RRoomInfoBean bean = roomImpl.selectRoomById(param.getId());
        if (bean == null){
            throw new ServiceException("object_is_not_exist","影厅");
        }
        return bean;
    }

    private ROrderInfoBean getPrice(String roomId, String btime, String etime) {
        ROrderInfoBean bean = new ROrderInfoBean();
        double prices = 0.0f;
        String cal = "";
        RRoomPriceBean price = roomImpl.getPrice(roomId, btime, etime);
        do {
            int hour = NumUtil.toInt(price.getTimes().substring(0, 2), 0);
            if (hour>0) {
                prices += price.getPrice() * hour;
                if (cal.equals("")) {
                    cal += price.getPrice()+"*"+hour;
                } else {
                    cal += "+"+price.getPrice()+"*"+hour;
                }
            }
            int minute = NumUtil.toInt(price.getTimes().substring(3, 5), 0);
            if (minute > 15 && minute <= 30) {
                prices += 0.5 * price.getPrice();
                cal += "+"+price.getPrice()+"*0.5";
            } else if (minute > 30) {
                prices += price.getPrice();
                cal += "+"+price.getPrice()+"*1";
            }
            if (price.getIsOver() == 0) {
                price = roomImpl.getPrice(roomId, price.getPEndTime(), etime);
                if (price.getIsOver() == 1) {
                    hour = NumUtil.toInt(price.getTimes().substring(0, 2), 0);
                    if (hour>0) {
                        prices += price.getPrice() * hour;
                        cal += "+"+price.getPrice()+"*"+hour;
                    }
                    minute = NumUtil.toInt(price.getTimes().substring(3, 5), 0);
                    if (minute > 15 && minute <= 30) {
                        prices += 0.5 * price.getPrice();
                        cal += "+"+price.getPrice()+"*0.5";
                    } else if (minute > 30) {
                        prices += price.getPrice();
                        cal += "+"+price.getPrice()+"*1";
                    }
                }
            }
        } while (price.getIsOver() == 0);
        bean.setMoney(prices);
        bean.setCalculate(cal);
        return bean;
    }

    /**
     * 验证影厅在接下来的时间内是否可以使用
     * @param room
     * @param etime 结束时间
     * @param phoneNum 当前查询用户的手机号
     * @return
     */
    private boolean isValidOfRoom(RRoomInfoBean room, Timestamp etime, String phoneNum) {
        List<RRoomBookInfoBean> bookList = roomImpl.getRoomBookList(room.getId());
        if (bookList.size() == 0)
            return true;
        RRoomBookInfoBean book = bookList.get(0);
        if (book.getStartTime()>DateTimeUtil.formatTimestamp(etime))
            return true;
        if (book.getPhoneNum().equals(phoneNum))
            return true;
        return false;
    }
}
